Automatic Deployments: Install CodeDeploy Agent on EC2
We will be installing CodeDeploy agent on our EC2 instance in this lesson.
We'll cover the following
The deployment pipeline#
Now it’s time to create the deployment pipeline in CloudFormation. Let’s start by setting up a few environment variables in our deploy-infra.sh
script with information about our GitHub credentials.
And then we can pass these variables to our main.yml
script as parameters.
To do that, we also need to update the Parameters
section in main.yml
to receive the GitHub information.
Next, we need to add a new managed policy to allow our EC2 instance to access CodeDeploy.
Line #14: Allows our EC2 instance to access CodeDeploy.
We also need to create a new IAM role to allow the CodeBuild, CodeDeploy, and CodePipeline services to access our AWS resources.
Then we can define our CodeBuild project.
Next, we can define our CodeDeploy application. This lets CodeDeploy know that our deployment target is EC2.
Line #5: In this case, Server
means EC2.
To complete the CodeDeploy setup, we also need to define a deployment group. For now, we’re going to have one deployment group called Staging. This will be our pre-production environment. We will add another deployment group for production when we get to the Production section.
Line #7: For pre-production, we can choose to deploy as fast as possible. We’ll do this differently in production.
Line #9: These filters define how CodeDeploy will find the EC2 instances to deploy to.
And finally, we just need to define our pipeline. Let’s do that in the next lesson.